package com.dly.blog.config;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/19 9:53
 */
@Configuration
public class Config {

    /**
     * 创建一个线程池
     *  1. 5个核心线程
     *  2. 10个最大线程
     *  3. 达到最大线程后 多久没有操作 销毁线程
     *  4. 时间单位
     *  5. 队列大小 限制为 1024
     *  6. 线程工厂创建线程
     *  7. 拒绝策略
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    public ExecutorService makePool(){
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNamePrefix("hutool-pool").setDaemon(true).build();
        return new ThreadPoolExecutor(5,10,100L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(1024), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
